<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <style>
     
  </style>
  <body>
    <input type="text" name="" id="" />
    <input type="text" name="" id="" />
    <input type="button" name="" id="" value="登录" />

    <script src="axios.min.js"></script>
    <script>
      let inp = document.querySelectorAll("input");
      inp[2].onclick = function () {
        let username = inp[0].value;
        let password = inp[1].value;

        axios
          .get("http://jx.xuzhixiang.top/ap/api/login.php", {
            params: {
              username: username,
              password: password,
            },
          })
          .then((r) => {
            let rr = r.data;
            console.log(rr.data.id);

            if (rr.code == 1) {
              // localStorage.setItem("id",rr.data.id)
              let { id, token, username } = rr.data;
              localStorage.setItem("id", id);
              // console.log(id);
              localStorage.setItem("token", token);
              localStorage.setItem("username", username);

              alert(rr.msg);
              location.href = "首页1.html";
            } else {
              alert(rr.msg);
            }
          });
      };
    </script>
  </body>
</html>
